package com.fbs.wowo.manage.mapper;

import com.fbs.wowo.manage.entity.Account;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

public interface AccountMapper {
    @Delete({
        "delete from account",
        "where id = #{id,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(String id);

    @InsertProvider(type=AccountSqlProvider.class, method="insertSelective")
    int insertSelective(Account record);

    @Select({
        "select",
        "id, user_id, address, public_key, private_key, password, salt, balance, lock_balance",
        "from account",
        "where id = #{id,jdbcType=VARCHAR}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="user_id", property="userId", jdbcType=JdbcType.VARCHAR),
        @Result(column="address", property="address", jdbcType=JdbcType.VARCHAR),
        @Result(column="public_key", property="publicKey", jdbcType=JdbcType.VARCHAR),
        @Result(column="private_key", property="privateKey", jdbcType=JdbcType.VARCHAR),
        @Result(column="password", property="password", jdbcType=JdbcType.VARCHAR),
        @Result(column="salt", property="salt", jdbcType=JdbcType.VARCHAR),
        @Result(column="balance", property="balance", jdbcType=JdbcType.DECIMAL),
        @Result(column="lock_balance", property="lockBalance", jdbcType=JdbcType.DECIMAL)
    })
    Account selectByPrimaryKey(String id);

    @UpdateProvider(type=AccountSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Account record);

    /**
     * 按账户userId查找Account
     */
    @Select({
            "select",
            "id, user_id, address, public_key, private_key, password, salt, balance, lock_balance",
            "from account",
            "where user_id = #{userId,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.VARCHAR, id=true),
            @Result(column="user_id", property="userId", jdbcType=JdbcType.VARCHAR),
            @Result(column="address", property="address", jdbcType=JdbcType.VARCHAR),
            @Result(column="public_key", property="publicKey", jdbcType=JdbcType.VARCHAR),
            @Result(column="private_key", property="privateKey", jdbcType=JdbcType.VARCHAR),
            @Result(column="password", property="password", jdbcType=JdbcType.VARCHAR),
            @Result(column="salt", property="salt", jdbcType=JdbcType.VARCHAR),
            @Result(column="balance", property="balance", jdbcType=JdbcType.DECIMAL),
            @Result(column="lock_balance", property="lockBalance", jdbcType=JdbcType.DECIMAL)
    })
    Account findByUserId(String userId);
}